import Vue from "vue";
import Router from "vue-router";
import Layout from "./views/Layout/Layout.vue";
import store from "@/store/index";

Vue.use(Router);
const routes = [
  {
    path: "/",
    component: Layout,
    redirect: "index",
    children: [
      {
        path: "index",
        name: "home",
        component: () =>
          import(/* webpackChunkName: "about" */ "@/views/Admins/Index.vue")
      },
      {
        path: "roles",
        name: "about",
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () =>
          import(/* webpackChunkName: "about" */ "./views/About.vue")
      }
    ]
  },
  {
    path: "/login",
    component: () => import("@/views/Login/Login.vue"),
    name: "login",
    meta: {
      login: false
    }
  }
];

const router = new Router({
  // mode: "history",
  base: process.env.BASE_URL,
  routes
});
router.beforeEach((to, from, next) => {
  if (to.meta.login === false) {
    //不需要登陆验证
  } else {
    store.dispatch("account/pullInfo");
  }
  next();
});
export default router;
